<template>
	<view>
		<view class="form">
			<u-form :model="form" ref="uForm">
				<u-form-item label="姓名" label-width="150rpx">
					<u-input v-model="form.name" placeholder="请输入姓名" />
				</u-form-item>
				<u-form-item label="性别" label-width="150rpx">
					<u-input v-model="sex_text" type="select" @click="sexShow=true" placeholder="请选择" />
				</u-form-item>
				<u-form-item label="年龄" label-width="150rpx">
					<u-input v-model="form.age" type="number" placeholder="请输入" />
				</u-form-item>
				<u-form-item label="学历" label-width="150rpx">
					<u-input v-model="xueli_text" type="select" @click="xueliShow=true" placeholder="请选择" />
				</u-form-item>
				<u-form-item label="工作经验" label-width="150rpx">
					<u-input v-model="jobExpisre_text" type="select" @click="expShow=true" placeholder="请选择" />
				</u-form-item>
				<u-form-item label="联系电话" label-width="150rpx">
					<u-input v-model="form.contactPhone" placeholder="请输入" />
				</u-form-item>
				<u-form-item label="期望职位" label-width="150rpx">
					<u-input v-model="jobClassId_name" @click="show()" type="select" placeholder="请选择" />
				</u-form-item>
				<u-form-item label="自我介绍" label-width="150rpx" label-position="top">
					<u-input v-model="form.remark" type="textarea" height="200" :maxlength="-1"
						placeholder="请填写工作经验和特长，描述您在工作中具体负责事项和业绩，清晰具体的工作经历更容易获得求职机会。(最少不小于10个字)" />
				</u-form-item>
			</u-form>
		</view>
		<u-select v-model="sexShow" :list="sexData" @confirm="confirmsex"></u-select>
		<u-select v-model="xueliShow" :list="xueliData" @confirm="confirmxueli"></u-select>
		<u-select v-model="expShow" :list="expData" @confirm="confirmExp"></u-select>
		<jobSelect ref="jobSelect" :listData="listData" @confirem="confiremJob"></jobSelect>
		<view style="height: 120rpx;"></view>
		<botbtn :btntext="nodata?'立即创建':'编辑简历'" @confirem="submit"></botbtn>
	</view>
</template>

<script>
	import jobSelect from '@/components/yunmiao-jobSelect/yunmiao-jobSelect.vue'
	import botbtn from '@/components/Botbtn/Botbtn.vue'
	export default {
		components: {
			jobSelect,
			botbtn
		},
		data() {
			return {
				form: {
					name: '',
					sex: '',
					age: '',
					xueli: '',
					jobExpisre: '',
					contactPhone: '',
					jobClassId: '',
					remark: '',
				},
				xueli_text: '',
				jobExpisre_text: '',
				sexShow: false,
				sexData: [{
					value: '男',
					label: '男'
				}, {
					value: '女',
					label: '女'
				}],
				xueliShow: false,
				xueliData: [{
						value: '初中',
						label: '初中'
					},
					{
						value: '高中/中专',
						label: '高中/中专'
					},
					{
						value: '大专',
						label: '大专'
					},
					{
						value: '本科',
						label: '本科'
					},
					{
						value: '本科以上',
						label: '本科以上'
					}
				],
				expShow: false,
				expData: [{
					value: '1年以下',
					label: '1年以下'
				}, {
					value: '1-3年',
					label: '1-3年'
				}, {
					value: '3-5年',
					label: '3-5年'
				}, {
					value: '5-8年',
					label: '5-8年'
				}, {
					value: '8年以上',
					label: '8年以上'
				}],
				listData: [],
				jobClassId_name: '',
				sex_text: '',
				nodata: false,
			}
		},
		onLoad() {
			this.getJobCategory()
			this.getResume()
		},
		methods: {
			getJobCategory() {
				this.$u.get('/home/job/getJobCategory', {

				}).then(res => {
					this.listData = res;
				})
			},
			getResume() {
				this.$u.get('/my/userCard', {

				}).then(res => {
					if (res) {
						this.nodata = false;
						this.form = {
						    id: res.id,
							name: res.name,
							sex: res.sex,
							age: res.age,
							xueli: res.xueli,
							jobExpisre: res.jobExpisre,
							contactPhone: res.contactPhone,
							jobClassId: res.jobClassId,
							remark: res.remark,
						};
						this.sex_text = res.sex;
						this.xueli_text = res.xueli;
						this.jobExpisre_text = res.jobExpisre;
						this.jobClassId_name = res.jobcategory.name;
					} else {
						this.nodata = true;
					}
				})
			},
			show() {
				this.$refs.jobSelect.show()
			},
			confiremJob(e) {
				this.form.jobClassId = e.code;
				this.jobClassId_name = e.name;
			},
			confirmxueli(e) {
				this.xueli_text = e[0].label;
				this.form.xueli = e[0].value;
			},
			confirmExp(e) {
				this.jobExpisre_text = e[0].label;
				this.form.jobExpisre = e[0].value;
			},
			confirmsex(e) {
				this.sex_text = e[0].label;
				this.form.sex = e[0].value;
			},
			submit() {
				if (this.form.name == '') {
					return this.$u.toast('请输入姓名')
				}
				if (this.form.sex == '') {
					return this.$u.toast('填选择性别')
				}
				if (this.form.xueli == '') {
					return this.$u.toast('请选择学历')
				}
				if (this.form.jobExpisre == '') {
					return this.$u.toast('请选择工作经验')
				}
				if (this.form.contactPhone == '') {
					return this.$u.toast('请输入联系电话')
				}
				if (!this.$u.test.mobile(this.form.contactPhone)) {
					return this.$u.toast('请输入正确的联系电话')
				}
				if (this.form.jobClassId == '') {
					return this.$u.toast('请选择期望职位')
				}
				if (this.form.remark == '') {
					return this.$u.toast('请输入职位描述')
				}
				this.$u.post('tc/saveUserCard', this.form).then(res => {
					this.$u.route({
						type: 'redirectTo',
						url: '/pagesPush/push_result/push_result',
						params: {
							type: 'resume'
						}
					});
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.form {
		padding: 20rpx;
		background-color: white;

		.form-label {
			padding-bottom: 20rpx;
		}
	}
</style>
